package java_thinking.unit_21.concurrentutil;

/**
 *
 * @author: cww
 * @DateTime: 2019-08-11 9:52
 */

/**
 *      LockSupport 见visio
 */
public class LockTheory {
    private static String s1 = "s1";
    private static String s2 = "s2";
    public static void main(String[] args) {
        Thread t1 = new Thread(() -> {
            synchronized (s1){
                try {
                    Thread.sleep(2000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                synchronized (s2) {
                    System.out.println("s1 -> s2");
                }
            }

        },"t1");

        Thread t2 = new Thread(() -> {
            synchronized (s2){
                try {
                    Thread.sleep(2000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                synchronized (s1){
                    System.out.println("s2 -> s1");
                }
            }
        }, "t2");
        t1.start();
        t2.start();

    }
}
